<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
	   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>HttpClient Examples</title>
<link rel="stylesheet" href="http://www.incutio.com/css/basic.css" type="text/css" />
<style type="text/css" media="screen">
@import "http://www.incutio.com/css/layout.css";
.leftmenu ul {
    margin: 0px;
    padding: 0px 0px 10px 15px;
    list-style-type: square;
}
h3 {
    margin-bottom: 1em;
}
dl {
    width: 80%;
    margin-left: 10px;
}
dt {
    font-weight: bold;
    line-height: 1.4em;
}
pre {
    margin: 15px;
    padding: 10px;
    border: 1px dashed #ccc;
    color: #006;
}
</style>
</head>

<body>
<div id="Header"><img id="IncutioLogo" src="/images/incutiologo.gif" alt="Logo: Incutio Limited, Be Inspired" /><img id="ScriptsLogo" src="/images/scriptslogo.gif" alt="scripts.incutio.com" /><div style="clear:both"></div></div>
<div id="TopNavBar">
<a href="http://www.incutio.com/">INCUTIO HOME</a><span> | </span>
<a href="http://scripts.incutio.com/">SCRIPTS</a><span> | </span>
<a href="http://www.incutio.com/contact/">CONTACT</a>
</div>
<div id="MainContentCell">
	<div id="MainBodyContent">

<h2>HttpClient Examples</h2>

<p><a href="index.php">HttpClient Home</a> | <a href="HttpClient.class.php" title="HttpClient.class.php">Download HttpClient (txt)</a> | <a href="manual.php">HttpClient Manual</a> | <a href="demo.php">HttpClient Demo</a></p></p>

<h3>Grabbing an HTML page (static method)</h3>

<pre><code>$pageContents = HttpClient::quickGet('http://example.com/');</code></pre>

<h3>Posting a form and grabbing the response (static method)</h3>

<pre><code>$pageContents = HttpClient::quickPost('http://example.com/someForm', array(
    'name' => 'Some Name',
    'email' => 'email@example.com'
));</code></pre>

<p>The static methods are easy to use, but seriously limit the functionality of the class as you cannot access returned headers or use facilities such as cookies or authentication.</p>

<h3>A simple GET request using the class</h3>

<pre><code>$client = new HttpClient('example.com');
if (!$client->get('/')) {
    die('An error occurred: '.$client->getError());
}
$pageContents = $client->getContent();</code></pre>

<h3>A GET request with debugging turned on</h3>

<pre><code>$client = new HttpClient('example.com');
$client->setDebug(true);
if (!$client->get('/')) {
    die('An error occurred: '.$client->getError());
}
$pageContents = $client->getContent();</code></pre>

<h3>A GET request demonstrating automatic redirection</h3>

<pre><code>$client = new HttpClient('www.amazon.com');
$client->setDebug(true);
if (!$client->get('/')) {
    die('An error occurred: '.$client->getError());
}
$pageContents = $client->getContent();</code></pre>

<h3>Check to see if a page exists</h3>

<pre><code>$client = new HttpClient('example.com');
$client->setDebug(true);
if (!$client->get('/thispagedoesnotexist')) {
    die('An error occurred: '.$client->getError());
}
if ($client->getStatus() == '404') {
    echo 'Page does not exist!';
}
$pageContents = $client->getContent();</code></pre>

<h3>Fake the User Agent string</h3>

<pre><code>$client = new HttpClient('example.com');
$client->setDebug(true);
$client->setUserAgent('Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.3a) Gecko/20021207');
if (!$client->get('/')) {
    die('An error occurred: '.$client->getError());
}
$pageContents = $client->getContent();</code></pre>

<h3>Log in to a site via a login form, then request a page</h3>

<p>In this example, it is assumed that correctly logging in will result in the server sending a sesssion cookie of some sort. This cookie is resent by the HttpClient class automatically, so a request to a page that requires users to be logged in will now work.</p>

<pre><code>$client = new HttpClient('example.com');
$client->post('/login.php', array(
    'username' => 'Simon',
    'password' => 'ducks'
));
if (!$client->get('/private.php')) {
    die('An error occurred: '.$client->getError());
}
$pageContents = $client->getContent();
</code></pre>

<h3>Using HTTP authorisation</h3>

<p>Note that the class uses the American spelling 'authorization' to fit with the <acronym title="HyperText Transfer Protocol">HTTP</acronym> specification.</p>

<pre><code>$client = new HttpClient('example.com');
$client->setAuthorization('Username', 'Password');
if (!$client->get('/')) {
    die('An error occurred: '.$client->getError());
}
$pageContents = $client->getContent();
</code></pre>

<h3>Print out the headers from a response</h3>

<pre><code>$client = new HttpClient('example.com');
if (!$client->get('/')) {
    die('An error occurred: '.$client->getError());
}
print_r($client->getHeaders());
</code></pre>

<h3>Setting the maximum number of redirects</h3>

<pre><code>$client = new HttpClient('www.amazon.com');
$client->setDebug(true);
$client->setMaxRedirects(3);
$client->get('/');
</code></pre>

	<div id="LeftMenu">
		<div class="fieldsetPartners">
				<span class="legendPartners">Scripts</span>
<div class="leftmenu">
<ul>
<li><a href="/">Scripts Home</a></li>
</ul>
<ul>
<li><a href="/xmlrpc/">PHP XML-RPC Library</a></li>
<li><a href="/amazon/">PHP Amazon Search</a></li>
<li><a href="/google/">PHP Google Web API</a></li>
</ul>
<ul>
<li><a href="/incDirectory/">incDirectory</a></li>
<li><a href="/sslinks/">ssLinks</a></li>

</ul>

<!-- BEGIN LivePerson Button Code --><table border='0' cellspacing='0' cellpadding='0'><tr><td align='center'><a href='http://server.iad.liveperson.net/hc/52472728/?cmd=file&file=visitorWantsToChat&site=52472728&byhref=1' target='chat52472728' onClick="javascript:window.open('http://server.iad.liveperson.net/hc/52472728/?cmd=file&file=visitorWantsToChat&site=52472728&referrer='+document.location,'chat52472728','width=472,height=320');return false;"><img src='http://server.iad.liveperson.net/hc/52472728/?cmd=repstate&site=52472728&category=en;woman;2&ver=1' name='hcIcon' width=110 border=0></a></td></tr></table><!-- END LivePerson Button code -->

</div>
		</div>
	</div>
	
		<div id="RightGutter">
			<div style="text-align: center;"><img src="../images/light.gif" alt="scripts.incutio.com light logo" style="width: 81px; margin-top: 10px"/></div>
		</div>
	</div>
	
</div>
<div id="Footer">
	Design, Content, Images &copy; 2002 Incutio Limited | <a href="http://validator.w3.org/check/referer">W3C XHTML 1.0</a>
</div>
<!-- BEGIN HumanTag Monitor. DO NOT MOVE! MUST BE PLACED JUST BEFORE THE /BODY TAG --><script language='javascript' src='http://server.iad.liveperson.net/hc/52472728/x.js?cmd=file&file=chatScript3&site=52472728&category=en;woman;2'> </script><!-- END HumanTag Monitor. DO NOT MOVE! MUST BE PLACED JUST BEFORE THE /BODY TAG -->
</body>
</html>